package com.tidc.foundprovider7001.service;

import com.tidc.foundprovider7001.mapper.*;
import com.tidc.foundprovider7001.ov.UserOV;
import com.tidc.foundprovider7001.pojo.*;
import com.tidc.foundprovider7001.utiles.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

/**
 * @ClassNmae LoginService
 * @Description TODO
 * @Author 14631
 **/
@Service
public class LoginService {
	@Autowired
	public UserMapper userMapper;
	@Autowired
	ApplicationContextProvider ac;
	@Autowired
	UserSession userSession;

//	public UserOV studentLogin(Student student, HttpServletRequest req,UserOV userOV){
//		student = userMapper.selectStudent(student);
//		if(student !=null){
//			//如果登录成功就存入Session
//			req.getSession().setAttribute("student", student);
//			userOV.setMessage("success").setCode(200);
//		}else {
//			userOV.setMessage("邮箱或密码错误").setCode(404);
//		}
//
//		return userOV;
//	}
//	public UserOV teacherLogin(Teacher teacher,HttpServletRequest req,UserOV userOV){
//		teacher = userMapper.selectTeacher(teacher);
//		if(teacher!=null){
//			//如果登录成功就存入Session
//			req.getSession().setAttribute("teacher",teacher);
//			userOV.setMessage("success").setCode(200);
//		}else{
//			userOV.setMessage("用户名或密码错误").setCode(404);
//		}
//
//
//		return userOV;
//	}
	public UserOV getStudent(UserOV userOV, UserDetails userDetails){
		 if(userDetails.getUsername()!=null) {

			 Student student = userMapper.selectStudent(userDetails.getUsername());
			 Teacher teacher = userMapper.selectTeacher(userDetails.getUsername());

			 if(student!=null){
				 student.setPassword("");
				 userOV.setCode(201).setData(student).setMessage("获取成功").setData(student);
			 }
			 if(teacher!=null){
				 teacher.setPassword("");
				 userOV.setCode(200).setData(student).setMessage("获取成功").setData(teacher);
			 }
			 return userOV;
		}
		 	userOV.setCode(404).setMessage("用户未登录");

		return userOV;
	}
//	public UserOV getTeacher(UserOV userOV,HttpServletRequest req){
//		userOV = userSession.Session("teacher",userOV,req);
//		return userOV;
//	}
}
